package chapter08

object Test03_MatchTupleExtend {
  def main(args: Array[String]): Unit = {
    // 1.在变量声明时匹配
    val (x, y) = (10, "hello")
    println(s"$x,$y")

    val List(first, second, _*) = List(23, 15, 45, 748)
    println(s"first:$first,second :$second")

    val fir :: sec :: rest = List(23, 15, 45, 748)
    println(s"first:$fir,second :$sec,rest:$rest")

    //2. for 推导式中进行模式匹配
    val list = List(("zhang", 1233),("a",33))
    // 2.1遍历方式1
    for (elem <- list) {
      println(elem._1 + ":" + elem._2)
    }
    // 2.2遍历方式2
    for ((a,b) <- list) {
      println(a + ":" + b)
    }

    //2.3 可以不考虑某个位置的变量，之遍历key或value
    for ((a,_) <- list) {
      println(a)
    }

    //2.4 可以指定某个位置的值必须是多少,用作筛选
    for (("a",b) <- list) {
      println(b)
    }
  }
}
